<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
// checks to see if password session is set
// if not redirects to ../admin/
if($_SESSION['loggedIn'] == 0 && !isset($adminPage)){
include('../includes/auth.inc.php');
}

if (isset($_POST['wd_updated'])) {

	// check to see if details have been completed
	if (empty($_POST['wd_title']) || empty($_POST['wd_url']) || empty($_POST['wd_description'])) {
	$error = 1;

	} else {
	
	$sql =  sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'adLinkTitle'",
			   quote_smart($_POST['wd_title']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	$sql =  sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'adLinkURL'",
			   quote_smart($_POST['wd_url']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	$sql =  sprintf("UPDATE affiliSt_config SET value = %s WHERE name = 'adLinkDescription'",
			   quote_smart($_POST['wd_description']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	
	}
}


$getUserDetails = mysql_query("SELECT * FROM affiliSt_config");
$userDetails = mysql_fetch_assoc($getUserDetails);

$getMyLinkTitle = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adLinkTitle'");
$myLinkTitle = mysql_fetch_assoc($getMyLinkTitle);
$getMyLinkURL = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adLinkURL'");
$myLinkURL = mysql_fetch_assoc($getMyLinkURL);
$getMyLinkDesc = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adLinkDescription'");
$myLinkDesc = mysql_fetch_assoc($getMyLinkDesc);












?>


<?php
// error report
if ($error == 1) {
echo '<fieldset><strong style="color:red">ERROR: Fields must not be empty</strong></fieldset>';
} else {
	if (isset($_POST['wd_updated'])) {
	echo '<fieldset><strong style="color:green">Link Details Updated</strong></fieldset>';
	}
}
?>



<fieldset>
<legend>Update Your Link Details</legend>
<form action="index.php?ad=ldu" method="post" name="updateDetails">

<table cellpadding="4" cellspacing="0" border="0">
<?php do { ?>
<?php if ($userDetails['name'] == 'adLinkTitle') { ?>
<tr>
<td>
<label for="wTitle">Your Website Title:</label>
</td>
<td>
<input name="wd_title" type="text" id="wTitle" class="adminInput" value="<?php echo $userDetails['value'];?>" />
</td>
</tr>
<?php } ?>
<?php if ($userDetails['name'] == 'adLinkURL') { ?>
<tr>
<td>
<label for="wAddress">Your Backlink URL:</label>
</td>
<td>
<input name="wd_url" type="text" id="wAddress" class="adminInput" value="<?php echo $userDetails['value'];?>" />
</td>
</tr>
<?php } ?>
<?php if ($userDetails['name'] == 'adLinkDescription') { ?>
<tr>
<td>
<label for="wAddress">Your Website Description:</label>
</td>
<td>
<textarea name="wd_description" id="wDescription" class="adminInput"  rows="6"><?php echo $userDetails['value'];?></textarea>
</td>
</tr>
<?php } ?>
<?php } while ($userDetails = mysql_fetch_assoc($getUserDetails)); ?>
</table>
<input type="hidden" name="wd_updated" value="yes" />
<input value="Update Your Link Details" type="submit" class="padSubmit" />
</form>
<br />

<div id="myLink">
&lt;a href="<?php echo $myLinkURL['value']; ?>" target="_blank"&gt;<?php echo $myLinkTitle['value']; ?>&lt;/a&gt;&lt;br /&gt;<br />
<?php echo $myLinkDesc['value']; ?>
</div>



</fieldset>